package com.sld.cloudalibaba.controller;

import com.sld.cloudalibaba.pojo.Payment;
import com.sld.cloudalibaba.vojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/consumer")
public class OrderController {

    @Value("${service-url.nacos-user-service}")
    private String server_url;

    @Resource
    private RestTemplate restTemplate;


    @GetMapping("/payment")
    public Result save( Payment payment){
        return restTemplate.postForObject(server_url+"payment",payment,Result.class);
    }

    @GetMapping("/payment/{id}")
    public Result getPaymentById(@PathVariable("id") Long id){
        return restTemplate.getForObject(server_url+"payment/"+id,Result.class,id);
    }


}
